﻿using MongoDB.Bson.Serialization.Serializers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBase.util {
    public class MyMath {

      public static  bool agvSameDir(int p1x, int p1y, int p2x, int p2y, int p3x, int p3y) {//数学上三点不共线，小车可以快速通过

            int v1x = p2x - p1x;
            int v1y = p2y - p1y;
            if (v1x == 0 && v1y == 0) {
                return true;
            }
            int v2x = p3x - p2x;
            int v2y = p3y - p2y;
            if (v2x == 0 && v2y == 0) {
                return true;
            }
            if (v1x == 0) {
                if (v2x == 0) {
                    if (v2y * v1y >0) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    if (v2y * v1y <= 0) {
                        return false;
                    }
                    double d = v2y*1.0 / v2x;
                    if (d < 0.01&&d>-0.01) {
                        return true;
                    } else {
                        return false;
                    }
                }
            } else {
                if (v1y == 0) {
                    if (v2x * v1x <= 0) {
                        return false;
                    }
                    double d = v2y * 1.0 / v2x;
                    if (d < 0.01 && d > -0.01) {
                        return true;
                    } else {
                        return false;
                    }
                } else {
                    double vy2s = v1x * 1.0 / v2x * v2y;
                    if (v1x * v2x < 0) {
                        vy2s = -vy2s;
                    }

                    double d = (vy2s - v1y) / v1y;
                    if (d < 0.01 && d > -0.01) {
                        return true;
                    } else {
                        return false;
                    }

                }
            }
        }
    }
}
